WPS Office.apk(点击下载) / znj.java


package defpackage;

import android.content.Context;
import android.content.SharedPreferences;
import com.appsflyer.AppsFlyerProperties;
import com.baidu.tts.loopj.AsyncHttpResponseHandler;
import com.baidu.tts.loopj.RequestParams;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.iflytek.cloud.SpeechEvent;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

/* renamed from: znj  reason: default package */
public final class znj {
    private static final String TAG = (zna.TAG + "_SyncConfig");

    public static void a(final int i, final String str, final String str2, final Context context) {
        new Thread() {
            /* class defpackage.znj.AnonymousClass1 */

            public final void run() {
                if (znj.cg(context)) {
                    JSONObject f = znj.f(i, str, str2, znf.kW(context).gOF());
                    if (f == null) {
                        try {
                            znm.b(znj.TAG, "Post sync request failed.", new Object[0]);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    } else {
                        znm.b(znj.TAG, "Post sync request success.", new Object[0]);
                        if (f.getBoolean(FirebaseAnalytics.Param.SUCCESS)) {
                            JSONObject jSONObject = f.getJSONObject(SpeechEvent.KEY_EVENT_RECORD_DATA);
                            if (jSONObject != null) {
                                znm.b(znj.TAG, "Server side sync configuration is :" + jSONObject.toString(), new Object[0]);
                                znj.c(jSONObject, context);
                            } else {
                                znm.d(znj.TAG, "There are no events on the server.", new Object[0]);
                            }
                        } else {
                            znm.b(znj.TAG, "Request format error.", new Object[0]);
                        }
                        znj.cS(context, "LastSyncTime");
                    }
                } else {
                    znm.b(znj.TAG, "Request time has not arrived, don't request.", new Object[0]);
                }
            }
        }.start();
    }

    static /* synthetic */ void c(JSONObject jSONObject, Context context) throws Exception {
        if (jSONObject.has("user_app_info")) {
            long j = ((long) jSONObject.getInt("user_app_info")) * 3600000;
            long cR = cR(context, "appInfoFrequency");
            if (cR != j) {
                znm.b(TAG, "appInfoFrequency" + " frequency changed from " + cR + " to " + j, new Object[0]);
                SharedPreferences.Editor edit = context.getSharedPreferences("sd", 0).edit();
                edit.putLong("appInfoFrequency", j);
                edit.commit();
                return;
            }
            znm.b(TAG, "appInfoFrequency" + " frequency does not change.", new Object[0]);
        }
    }

    private static long cR(Context context, String str) {
        return context.getSharedPreferences("sd", 0).getLong(str, 0);
    }

    public static void cS(Context context, String str) {
        SharedPreferences.Editor edit = context.getSharedPreferences("sd", 0).edit();
        edit.putLong(str, System.currentTimeMillis());
        edit.commit();
    }

    static /* synthetic */ boolean cg(Context context) {
        long cR = cR(context, "LastSyncTime");
        long currentTimeMillis = System.currentTimeMillis();
        znm.b(TAG, "last sync time is: " + cR + ". current time is: " + currentTimeMillis + " Sync interval is:86400000", new Object[0]);
        if (Math.abs(currentTimeMillis - cR) >= 86400000) {
            znm.b(TAG, "It is time to sync with server for event collection frequency", new Object[0]);
            return true;
        }
        znm.b(TAG, "It is not time to sync with server for event collection frequency", new Object[0]);
        return false;
    }

    public static JSONObject f(int i, String str, String str2, String str3) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("cid", i);
            if (str == null) {
                str = "";
            }
            jSONObject.put("sub_cid", str);
            if (str2 == null) {
                str2 = "";
            }
            jSONObject.put(AppsFlyerProperties.CHANNEL, str2);
            if (str3 == null) {
                str3 = "";
            }
            jSONObject.put("version", str3);
            znm.b(TAG, "Send to sync server parameter is: " + jSONObject.toString(), new Object[0]);
            try {
                DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
                HttpPost httpPost = new HttpPost("https://event.ksosoft.com/list");
                httpPost.setEntity(new StringEntity(jSONObject.toString()));
                httpPost.setHeader("Accept", RequestParams.APPLICATION_JSON);
                httpPost.setHeader("Content-type", RequestParams.APPLICATION_JSON);
                HttpResponse execute = defaultHttpClient.execute(httpPost);
                int statusCode = execute.getStatusLine().getStatusCode();
                if (statusCode == 200) {
                    return new JSONObject(EntityUtils.toString(execute.getEntity(), AsyncHttpResponseHandler.DEFAULT_CHARSET));
                }
                znm.d(TAG, "send http post failed, status code: " + statusCode, new Object[0]);
                return null;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        } catch (JSONException e2) {
            e2.printStackTrace();
            return null;
        }
    }
}